// pages/orderMsg/orderMsg.js
var server = require('../../utils/server');
import {
  formatDateTimeCN,
  formatDateCN
} from "../../utils/util"
const XLSX = require('../../utils/xlsx.mini.min');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageShow: false,
    tableData: [],
    columns: [
      { title: '产品', key: 'product', width: '300rpx' },
      { title: '规格', key: 'specifications', width: '300rpx' },
      { title: '是否新品', key: 'isNewProduct', class: 'newProduct', width: '100rpx' }, // class可以修改单元样式
      { title: '预估利润', key: 'estimatedProfit', class: 'estimatedProfit', width: '300rpx' },
      { title: '订单日', key: 'oderDay', class: 'oderDay', width: '300rpx' },
    ],
    fileType2Columns: [
      { title: '连锁店铺名称', key: 'chainStoreName', width: '300rpx', type: 'text' },
      { title: '类别', key: 'category', width: '100rpx', type: 'text' },
      { title: '店铺数量', key: 'storeNumber', width: '100rpx', type: 'text' },
      { title: '美团/大众点评店铺平均评分', key: 'averageScore', width: '300rpx', type: 'text' },
      { title: '有效期', key: 'validityPeriod', width: '150rpx', type: 'text' },
      { title: '使用时间', key: 'useTime', width: '150rpx', type: 'text' },
      { title: '可使用分布城市', key: 'distributedCities', width: '200rpx', type: 'text' },
      { title: '产品名称及套餐内容', key: 'productName', width: '300rpx', type: 'text' },
      { title: '价值', key: 'price', width: '100rpx', type: 'text' },
      { title: '数量', key: 'num', width: '150rpx', type: 'text' },
      { title: '使用权益', key: 'useRights', width: '200rpx', type: 'text' },
      { title: '卡券形式', key: 'couponForm', width: '300rpx', type: 'text' },
      { title: '使用限制', key: 'usageRestrictions', width: '300rpx', type: 'text' },
      { title: '售卖要求', key: 'sellRequirements', width: '300rpx', type: 'text' },
      { title: '产品/店铺链接（美团、携程等）', key: 'storeLinks', width: '300rpx', type: 'copy-text' },
      { title: '核销流程', key: 'verificationProcess', width: '300rpx', type: 'text' },
      { title: '实际成交价', key: 'finalPrice', width: '300rpx', type: 'text' },
      { title: '实际成交总价', key: 'finalTotalPrice', width: '300rpx', type: 'text', },
      { title: '旗舰店价格', key: 'flagshipstorePrice', width: '300rpx', type: 'text', },
      { title: '旗舰店粉丝量', key: 'flagshipstoreFans', width: '300rpx', type: 'text', },
      { title: '销量', key: 'salesNum', width: '300rpx', type: 'text', },
      { title: '评价', key: 'evaluateContent', width: '300rpx', type: 'text', },
      { title: '最低价', key: 'lowestPrice', width: '300rpx', type: 'text', },
      { title: '链接', key: 'link', width: '300rpx', type: 'text', }
    ],
    fileType3Columns: [
      { title: '酒店名称', key: 'hotelName', width: '200rpx', type: 'text' },
      { title: '酒店地址', key: 'hotelAddress', width: '200rpx', type: 'text' },
      { title: '旺季时间', key: 'busyTime', width: '100rpx', type: 'text' },
      { title: '房型', key: 'hotelType', width: '100rpx', type: 'text' },
      { title: '有效期', key: 'expirationDate', width: '100rpx', type: 'text' },
      { title: '是否含早', key: 'isHaveMorning', width: '100rpx', type: 'text' },
      { title: '数量', key: 'num', width: '100rpx', type: 'text' },
      { title: '平台价', key: 'price', width: '200rpx', type: 'text' },
      { title: '链接', key: 'url', width: '300rpx', type: 'copy-text' },
      { title: '房间图片', key: 'hotelPic', width: '100rpx', type: 'pic' },
      { title: '实际成交价', key: 'realPrice', width: '150rpx', type: 'text' },
      { title: '实际成交总价', key: 'finalTotalPrice', width: '300rpx', type: 'text', },
      { title: '旗舰店价格', key: 'flagshipstorePrice', width: '300rpx', type: 'text', },
      { title: '旗舰店粉丝量', key: 'flagshipstoreFans', width: '300rpx', type: 'text', },
      { title: '销量', key: 'salesNum', width: '300rpx', type: 'text', },
      { title: '评价', key: 'evaluateContent', width: '300rpx', type: 'text', },
      { title: '最低价', key: 'lowestPrice', width: '300rpx', type: 'text', },
      { title: '链接', key: 'link', width: '300rpx', type: 'text', }
    ],
    tableYHeight: 500,
    orderId: null,
    showName: new Date().toLocaleDateString(),
    userInfo: {},
    filePath: '',
    selectUserList: [],
    channelIds: '',
    showType: null,
    chooseUserList: [],
    chooseZhuliUserList: [],
    zhuliList: [],
    orderMsg: null,
    taskAllType: true,
    blindBoxPrice: null,
    showGoodMsgIndex: 0,
    goodList: [],
    inputPricePercent: 0,
    totalPrice: 0,
    showTitle: '',
    channelGoodPriceList: [],
    date: '点击选择日期',
    time: '点击选择时间',
    pushBiddingType: 1, //默认为1, 2为第一次竞价时的分配渠道
    endTime: '',
    submitCommitButton: '提交',
    showSubmitCommitButton: false,
    hasPushButton: true,
    projectName: '',
    checkMsg: {
      remark: '',
      costPrice: '',
      cashPrice: '',
    },
    chooseGoodList: [],
    chooseGoodTitle: [],
    chooseGoodDiscoutType: 1,
    discountGood: 1,
    goodColumns: [],
    goodDiscount: null,
    goodTotalDiscount: 0,
    goodTotalDiscount2: 0,
    hasJoinBidding: 1,
    hasAddJoinBidding: 1,
    startDateString: '',
    startTimeString: '00:00',
    refuseRemark: '',
    blindBoxRealPrice: '',
    saleRealPrice: '',
    totalRealPrice: '',
    realRemark: '',
    projectOutGood: {
      time: '',
      projectOutGoodPrice: '',
      projectOutGoodRemark: '',
      projectOutGoodSomePrice: '',
    },
    projectOutGoodSubmitStatus: false,
    discountList: [ '折扣', '金额' ],
    discountIndex: 0,
    discountPrice: '',
    hasChannelRefuseShowing: true,
    refuseChannelUserName: "",
    toOrder: 1, // 跳转到订单详情的路径，1、正常，2、订单详情里的其他订单点击跳转进入
    pushUserIdsToUserType: false,
    orderStatusName: [],
    cashDiscountType: 2,
    cashDiscountTypeArr: [
      { id: 1, value: '折扣' },
      { id: 2, value: '金额' },
    ],
    currentCashDiscountTypeIndex: 1,
    costDiscountType: 2,
    costDiscountTypeArr: [
      { id: 1, value: '折扣' },
      { id: 2, value: '金额' },
    ],
    currentCostDiscountTypeIndex: 1,
    checkMsgListColumns: [
      { title: '核价-变现价格', key: 'checkCashPrice', width: '300rpx', type: 'text', },
      { title: '核价-建议成本', key: 'checkCostPrice', width: '200rpx', type: 'text', },
      { title: '备注', key: 'checkRemark', width: '300rpx', type: 'text', },
      { title: '日期', key: 'createDate', width: '300rpx', type: 'text', },
    ],
    businessRemarkColumns: [
      { title: '商务', key: 'businessName', width: '120rpx', type: 'text', },
      { title: '订单超时说明', key: 'content', width: '1000rpx', type: 'text', },
    ],
    businessRemarkReplyColumns: [
        { title: '开拓者', key: 'pioneerName', width: '120rpx', type: 'text', },
        { title: '处理意见', key: 'content', width: '1000rpx', type: 'text', },
    ],
    checkMsgListColumnsx: [],
    // confirmBtnShow: false,
    noChannelUserGoodListDTOS: true,
    noAssistantCheckList: true,
    // 处理意见
    handleRemark: '',
    // 更多操作弹窗
    showDialog: false,
    // 更多操作弹窗样式
    selectDialogStyle: '',
    // 反馈按钮loading
    confirmLoading: false,
    showSetRate: 1,
    setRateList: [],
    chooseSetRateId: null,
    cashDiscount: null,
  },

  // 重置订单-设置截止时间
  goReSettingOrderTime(){
    let that = this
    wx.showModal({
      title: '确认',
      content: '是否重置订单？',
      success (res) {
        if (res.confirm) {
          that.doReSettingOrderTime()
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  doReSettingOrderTime(){
    let params = {
      orderId: this.data.orderMsg.id,
    }
    wx.showLoading({
      title: '加载中',
      mask: true,
    })
    server.post("/app/user/doReSettingOrderTime", params).then(res => {
      if (res.key === 1000) {
        this.getOrderMsg()
        wx.showToast({
          title: '重置成功',
          icon: 'success',
          duration: 2000
        })
        this.setData({
          projectOutGoodSubmitStatus: false,
        })
      }
    });
  },

  // 重置订单
  goReSettingOrder(){
    let that = this
    wx.showModal({
      title: '确认',
      content: '是否重置订单？',
      success (res) {
        if (res.confirm) {
          that.doReSettingOrder()
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  doReSettingOrder(){
    let params = {
      orderId: this.data.orderMsg.id,
    }
    wx.showLoading({
      title: '加载中',
      mask: true,
    })
    server.post("/app/user/doReSettingOrder", params).then(res => {
      if (res.key === 1000) {
        this.getOrderMsg()
        wx.showToast({
          title: '重置成功',
          icon: 'success',
          duration: 2000
        })
        this.setData({
          projectOutGoodSubmitStatus: false,
        })
      }
    });
  },
// 放弃订单
goAbandonOrder(){
  let that = this
  wx.showModal({
    title: '确认',
    content: '是否放弃订单？',
    success (res) {
      if (res.confirm) {
        that.doAbandonOrder()
      } else if (res.cancel) {
        console.log('用户点击取消')
      }
    }
  })
},
// 处理说明
goHandleExplain() {
  this.setData({
    showType: 10,
  })
},
sureChannelHandleRemark(){
  let params = {
    orderId: this.data.orderId,
    content: this.data.handleRemark,
  }
  wx.showLoading({
    title: '加载中',
    mask: true,
  })
  server.post("/app/user/replyTimeOutRemark", params).then(res => {
    if (res.key === 1000) {
      this.getOrderMsg()
      wx.showToast({
        title: '提交成功',
        icon: 'success',
        duration: 2000
      })
    }
  });
  wx.hideLoading()
},
bindinputHandleRemark(e) {
  this.setData({
    handleRemark: e.detail.value
  })
},
doAbandonOrder(){
  let params = {
    orderId: this.data.orderMsg.id,
  }
  wx.showLoading({
    title: '加载中',
    mask: true,
  })
  server.post("/app/user/abandonOrder", params).then(res => {
    if (res.key === 1000) {
      this.getOrderMsg()
      wx.showToast({
        title: '已放弃订单',
        icon: 'success',
        duration: 2000
      })
    }
  });
},
  goChannelRefuse(){
    let that = this
    wx.showModal({
      title: '确认',
      content: '确定要拒绝吗？',
      success (res) {
        if (res.confirm) {
          that.doRefuseChannelOrder()
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  doRefuseChannelOrder(){
    let params = {
      orderId: this.data.orderMsg.id,
    }
    wx.showLoading({
      title: '加载中',
      mask: true,
    })
    server.post("/app/user/doRefuseChannelOrder", params).then(res => {
      if (res.key === 1000) {
        this.getOrderMsg()
        wx.showToast({
          title: '提交成功',
          icon: 'success',
          duration: 2000
        })
        this.setData({
          projectOutGoodSubmitStatus: false,
        })
      }
    });
    wx.hideLoading()
  },

  bindconfirmDiscountPrice(e){
    this.setData({
      discountPrice: e.detail.value
    })
  },
  bindblurDiscountPrice(e){
    this.setData({
      discountPrice: e.detail.value
    })
  },
  bindPickerChangeDiscountIndex(e){
    this.setData({
      discountIndex: e.detail.value
    })
  },
  sureChannelOutGood(){
    if(this.data.projectOutGoodSubmitStatus){
      wx.showToast({
        title: '请勿重复提交',
        icon: 'error',
        duration: 2000
      })
      return
    }
    let projectId = this.data.orderMsg.projectId
    let projectOutGood = this.data.projectOutGood
    if(!projectOutGood.time){
      wx.showToast({
        title: '请选择出货时间',
        icon: 'error',
        duration: 2000
      })
      return
    }
    if(!projectOutGood.projectOutGoodPrice){
      wx.showToast({
        title: '请输入出货货值',
        icon: 'error',
        duration: 2000
      })
      return
    }
    if(!projectOutGood.projectOutGoodSomePrice){
      wx.showToast({
        title: '请输入出货部分应收',
        icon: 'error',
        duration: 2000
      })
      return
    }
    if(!projectOutGood.projectOutGoodRemark){
      wx.showToast({
        title: '请输入出货备注',
        icon: 'error',
        duration: 2000
      })
      return
    }
    this.setData({
      projectOutGoodSubmitStatus: true,
    })
    let params = {
      projectId: projectId,
      time: projectOutGood.time,
      projectOutGoodPrice: projectOutGood.projectOutGoodPrice,
      projectOutGoodRemark: projectOutGood.projectOutGoodRemark,
      projectOutGoodSomePrice: projectOutGood.projectOutGoodSomePrice,
    }
    wx.showLoading({
      title: '加载中',
      mask: true,
    })
    server.post("/app/user/updateProjectOutGoodMsg", params).then(res => {
      if (res.key === 1000) {
        this.getOrderMsg()
        wx.showToast({
          title: '提交成功',
          icon: 'success',
          duration: 2000
        })
        this.setData({
          projectOutGoodSubmitStatus: false,
        })
      }
    });
    wx.hideLoading()
  },

  bindblurProjectOutGoodSomePrice(e){
    let val = e.detail.value
    let projectOutGood = this.data.projectOutGood
    projectOutGood.projectOutGoodSomePrice = val
    this.setData({
      projectOutGood: projectOutGood
    })
  },

  bindblurProjectOutGoodRemark(e){
    let val = e.detail.value
    let projectOutGood = this.data.projectOutGood
    projectOutGood.projectOutGoodRemark = val
    this.setData({
      projectOutGood: projectOutGood
    })
  },

  bindblurProjectOutGoodPrice(e){
    let val = e.detail.value
    let projectOutGood = this.data.projectOutGood
    projectOutGood.projectOutGoodPrice = val
    this.setData({
      projectOutGood: projectOutGood
    })
  },

  bindChangeProjectOutGood(e){
    let time = e.detail.value
    let projectOutGood = this.data.projectOutGood
    projectOutGood.date = time
    projectOutGood.time = new Date(time).getTime()
    this.setData({
      projectOutGood: projectOutGood
    })
  },
  goProjectOutGood(){
    this.setData({
      showType: 9,
      projectOutGood: {
        time: '',
        projectOutGoodPrice: '',
        projectOutGoodRemark: '',
        projectOutGoodSomePrice: '',
      },
    })
  },

  timeEnd(e){
    this.getOrderMsg()
    this.setData({
      leftTime: 0,
    })
  },

  sureChannelRealPrice(){
    let params = {
      orderId: this.data.orderId,
      blindBoxRealPrice: this.data.blindBoxRealPrice,
      saleRealPrice: this.data.saleRealPrice,
      realRemark: this.data.realRemark,
    }
    wx.showLoading({
      title: '加载中',
      mask: true,
    })
    server.post("/app/user/updateOrderRealPrice", params).then(res => {
      if (res.key === 1000) {
        this.getOrderMsg()
        wx.showToast({
          title: '提交成功',
          icon: 'success',
          duration: 2000
        })
      }
    });
    wx.hideLoading()
  },

  // 编辑盲盒实收，卖货实收
  goOrderRealCost(){
    this.setData({
      showType: 8,
      blindBoxRealPrice: this.data.orderMsg.blindRealPrice,
      saleRealPrice: this.data.orderMsg.saleRealPrice,
      totalRealPrice: Number(this.data.orderMsg.blindRealPrice) + Number(this.data.orderMsg.saleRealPrice),
      realRemark: this.data.orderMsg.realRemark,
    })
  },

  bindblurRealRemark(e){
    this.setData({
      realRemark: e.detail.value
    })
  },

  bindblurSaleRealPrice(e){
    this.setData({
      saleRealPrice: e.detail.value,
      totalRealPrice: Number(e.detail.value) + Number(this.data.blindBoxRealPrice)
    })
  },
  bindblurBlindBoxRealPrice(e){
    this.setData({
      blindBoxRealPrice: e.detail.value,
      totalRealPrice: Number(e.detail.value) + Number(this.data.saleRealPrice)
    })
  },

  sureChannelRefuseRemark(){
    let params = {
      orderId: this.data.orderId,
    }
    if(this.data.refuseRemark){
      params.reason = this.data.refuseRemark
    }
    wx.showLoading({
      title: '加载中',
      mask: true,
    })
    server.post("/app/user/refuseOrder", params).then(res => {
      if (res.key === 1000) {
        this.getOrderMsg()
        wx.showToast({
          title: '提交成功',
          icon: 'success',
          duration: 2000
        })
      }
    });
    wx.hideLoading()
  },
  goRefuseOrder(){
    //拒绝订单
    this.setData({
      showType: 7,
      refuseRemark: '',
    })
  },
  bindblurRefuseRemark(e){
    this.setData({
      refuseRemark: e.detail.value
    })
  },

  goBiddingTwoStartNext(){
    let params = {
      orderId: this.data.orderId,
    }
    wx.showLoading({
      title: '加载中',
      mask: true,
    })
    server.post("/app/user/startTwoBidding", params).then(res => {
      if (res.key === 1000) {
        this.getOrderMsg()
        wx.showToast({
          title: '发起成功',
          icon: 'success',
          duration: 2000
        })
      }
    });
    wx.hideLoading()
  },
  goBiddingTwoStart(){
    let that = this
    wx.showModal({
      title: '提示',
      content: '是否发起挑战',
      success (res) {
        if (res.confirm) {
          that.goBiddingTwoStartNext()
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  goBiddingTwoJoin(){
    let that = this
    wx.showModal({
      title: '提示',
      content: '是否参与挑战',
      success (res) {
        if (res.confirm) {
          that.goBiddingTwoJoinNext()
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  goBiddingTwoJoinNext(){
    let params = {
      orderId: this.data.orderId,
    }
    wx.showLoading({
      title: '加载中',
      mask: true,
    })
    server.post("/app/user/joinTwoBidding", params).then(res => {
      if (res.key === 1000) {
        this.getOrderMsg()
        wx.showToast({
          title: '发起成功',
          icon: 'success',
          duration: 2000
        })
      }
    });
    wx.hideLoading()
  },

  updateTotalPrice(){
    let totalPrice = 0
    let goodTotalDiscount = 0
    this.data.goodList.forEach(item => {
      totalPrice = totalPrice + (((item.goodSkuPrice || (!item.goodSkuPrice && item.goodSkuPrice == 0)) ? item.goodSkuPrice : item.price) * (item.goodSkuNum ? item.goodSkuNum : item.num))
      if(item.inputDiscount){
        if(this.data.chooseGoodDiscoutType == 2){
          goodTotalDiscount = goodTotalDiscount + (item.inputDiscount * (item.goodSkuNum ? item.goodSkuNum : item.num))
        }
      }
    })
    if(this.data.chooseGoodDiscoutType == 1){
      goodTotalDiscount = this.data.goodDiscount / 10 * totalPrice
    }
    this.setData({
      totalPrice: totalPrice.toFixed(2),
      goodTotalDiscount: goodTotalDiscount.toFixed(2)
    })
  },

  bindblurGoodDiscount(e){
    let that = this
    let discount = e.detail.value
    let list = this.data.goodList
    if(this.data.chooseGoodDiscoutType == 2){
      let totalPrice = 0
      list.forEach(item => {
        let a = (((item.goodSkuPrice || (!item.goodSkuPrice && item.goodSkuPrice == 0)) ? item.goodSkuPrice : item.price) * (item.goodSkuNum ? item.goodSkuNum : 0))
        totalPrice = totalPrice + a
      })
      console.log('=======', totalPrice)
      list.forEach(item => {
        let a = 0;
        if((item.goodSkuNum ? item.goodSkuNum : 0) > 0){
          a = discount * ((((item.goodSkuPrice || (!item.goodSkuPrice && item.goodSkuPrice == 0)) ? item.goodSkuPrice : item.price) * (item.goodSkuNum ? item.goodSkuNum : 0)) / totalPrice) / (item.goodSkuNum ? item.goodSkuNum : 0)
        }
        item.inputDiscount = a.toFixed(10)
        item.inputDiscountShow = a.toFixed(2)
        item.priceShow = (((item.goodSkuPrice || (!item.goodSkuPrice && item.goodSkuPrice == 0)) ? item.goodSkuPrice : item.price) - a).toFixed(2)
      })
    }else if(this.data.chooseGoodDiscoutType == 1){
      list.forEach(item => {
        item.inputDiscount = discount
        item.inputDiscountShow = discount
        item.priceShow = (((item.goodSkuPrice || (!item.goodSkuPrice && item.goodSkuPrice == 0)) ? item.goodSkuPrice : item.price) * (discount / 10)).toFixed(2)
      })
    }
    this.setData({
      goodDiscount: discount,
      goodList: list
    })
    setTimeout(()=>{
      that.updateTotalPrice()
    }, 100)
  },

  handleGoodDiscountItemChange(e){
    let val = e.detail.detail.value
    let index = e.detail.currentTarget.dataset.index
    let goodList = this.data.goodList
    goodList[index].inputDiscount = val
    goodList[index].inputDiscountShow = val
    this.setData({
      goodList: goodList,
    })
  },

  chooseGoodDiscoutTypeRadioChange(val){
    if(parseInt(val.detail.value) != this.data.chooseGoodDiscoutType){
      let list = this.data.goodList
      list.forEach(item => {
        item.inputDiscount = null
        item.inputDiscountShow = null
      })
      if(parseInt(val.detail.value) == 2){
        let goodColumns = [
          // { title: '单价', key: 'inputDiscountShow', width: '200rpx', type: 'input', },
          // { title: '折后单价', key: 'priceShow', width: '200rpx', type: 'input', },
          { title: '品牌', key: 'brandsValue', width: '300rpx', type: 'text', },
          { title: '商品名称', key: 'goodName', width: '300rpx', type: 'text', },
          { title: '有效期至', key: 'goodExpirationDate', width: '200rpx', type: 'text', },
          { title: '保质期', key: 'goodWarrantyDate', width: '200rpx', type: 'text', },
          { title: '规格', key: 'goodSku', width: '200rpx', type: 'text', },
          { title: '数量', key: 'goodSkuNum', width: '200rpx', type: 'text', },
          { title: '旗舰店售卖价', key: 'goodSkuPrice', width: '200rpx', type: 'text', },
          { title: '天猫/京东链接', key: 'goodOnlineLink', width: '300rpx', type: 'copy-text', },
          { title: '图片', key: 'goodSkuPic', width: '200rpx', type: 'pic', },
          { title: '箱规（数量）', key: 'goodBoxNum', width: '300rpx', type: 'text', },
          { title: '箱规（尺寸mm）', key: 'goodBoxSize', width: '300rpx', type: 'text', },
          { title: '单个产品包装尺寸mm', key: 'goodOneSize', width: '300rpx', type: 'text', },
          { title: '店铺粉丝量', key: 'shopFans', width: '300rpx', type: 'text', },
          { title: '产品销量', key: 'goodSaleNum', width: '300rpx', type: 'text', },
          { title: '实际成交价', key: 'finalPrice', width: '300rpx', type: 'text', },
          { title: '实际成交总价', key: 'finalTotalPrice', width: '300rpx', type: 'text', },
          { title: '旗舰店价格', key: 'flagshipstorePrice', width: '300rpx', type: 'text', },
          { title: '旗舰店粉丝量', key: 'flagshipstoreFans', width: '300rpx', type: 'text', },
          { title: '销量', key: 'salesNum', width: '300rpx', type: 'text', },
          { title: '评价', key: 'evaluateContent', width: '300rpx', type: 'text', },
          { title: '最低价', key: 'lowestPrice', width: '300rpx', type: 'text', },
          { title: '链接', key: 'link', width: '300rpx', type: 'text', }
        
        ]
        if(this.data.userInfo && this.data.userInfo.userType == 1){
          goodColumns = [
            // { title: '单价', key: 'inputDiscountShow', width: '200rpx', type: 'input', },
            // { title: '折后单价', key: 'priceShow', width: '200rpx', type: 'input', },
            { title: '品牌', key: 'brandsValue', width: '300rpx', type: 'text', },
            { title: '商品名称', key: 'goodName', width: '300rpx', type: 'text', },
            { title: '有效期至', key: 'goodExpirationDate', width: '200rpx', type: 'text', },
            { title: '保质期', key: 'goodWarrantyDate', width: '200rpx', type: 'text', },
            { title: '规格', key: 'goodSku', width: '200rpx', type: 'text', },
            { title: '数量', key: 'goodSkuNum', width: '200rpx', type: 'text', },
            { title: '旗舰店售卖价', key: 'goodSkuPrice', width: '200rpx', type: 'text', },
            { title: '天猫/京东链接', key: 'goodOnlineLink', width: '300rpx', type: 'copy-text', },
            { title: '图片', key: 'goodSkuPic', width: '200rpx', type: 'pic', },
          ]
        }
        if(this.data.orderMsg.fileType){
          let addColumns = [
            // { title: '单价', key: 'inputDiscountShow', width: '200rpx', type: 'input', },
            // { title: '折后单价', key: 'priceShow', width: '200rpx', type: 'input', },
          ]
          if(this.data.orderMsg.fileType == 2){
            goodColumns = addColumns.concat(this.data.fileType2Columns)
          }else if(this.data.orderMsg.fileType == 3){
            goodColumns = addColumns.concat(this.data.fileType3Columns)
          }
        }
        this.setData({
          goodColumns: goodColumns
        })
      }else{
        let goodColumns = [
          // { title: '折扣', key: 'inputDiscountShow', width: '200rpx', type: 'input', },
          // { title: '折后单价', key: 'priceShow', width: '200rpx', type: 'input', },
          { title: '品牌', key: 'brandsValue', width: '300rpx', type: 'text', },
          { title: '商品名称', key: 'goodName', width: '300rpx', type: 'text', },
          { title: '有效期至', key: 'goodExpirationDate', width: '200rpx', type: 'text', },
          { title: '保质期', key: 'goodWarrantyDate', width: '200rpx', type: 'text', },
          { title: '规格', key: 'goodSku', width: '200rpx', type: 'text', },
          { title: '数量', key: 'goodSkuNum', width: '200rpx', type: 'text', },
          { title: '旗舰店售卖价', key: 'goodSkuPrice', width: '200rpx', type: 'text', },
          { title: '天猫/京东链接', key: 'goodOnlineLink', width: '300rpx', type: 'copy-text', },
          { title: '图片', key: 'goodSkuPic', width: '200rpx', type: 'pic', },
          { title: '箱规（数量）', key: 'goodBoxNum', width: '300rpx', type: 'text', },
          { title: '箱规（尺寸mm）', key: 'goodBoxSize', width: '300rpx', type: 'text', },
          { title: '单个产品包装尺寸mm', key: 'goodOneSize', width: '300rpx', type: 'text', },
          { title: '店铺粉丝量', key: 'shopFans', width: '300rpx', type: 'text', },
          { title: '产品销量', key: 'goodSaleNum', width: '300rpx', type: 'text', },
          { title: '实际成交价', key: 'finalPrice', width: '300rpx', type: 'text', },
          { title: '实际成交总价', key: 'finalTotalPrice', width: '300rpx', type: 'text', },
          { title: '旗舰店价格', key: 'flagshipstorePrice', width: '300rpx', type: 'text', },
          { title: '旗舰店粉丝量', key: 'flagshipstoreFans', width: '300rpx', type: 'text', },
          { title: '销量', key: 'salesNum', width: '300rpx', type: 'text', },
          { title: '评价', key: 'evaluateContent', width: '300rpx', type: 'text', },
          { title: '最低价', key: 'lowestPrice', width: '300rpx', type: 'text', },
          { title: '链接', key: 'link', width: '300rpx', type: 'text', }
        ]
        if(this.data.userInfo && this.data.userInfo.userType == 1){
          goodColumns = [
            // { title: '折扣', key: 'inputDiscountShow', width: '200rpx', type: 'input', },
            // { title: '折后单价', key: 'priceShow', width: '200rpx', type: 'input', },
            { title: '品牌', key: 'brandsValue', width: '300rpx', type: 'text', },
            { title: '商品名称', key: 'goodName', width: '300rpx', type: 'text', },
            { title: '有效期至', key: 'goodExpirationDate', width: '200rpx', type: 'text', },
            { title: '保质期', key: 'goodWarrantyDate', width: '200rpx', type: 'text', },
            { title: '规格', key: 'goodSku', width: '200rpx', type: 'text', },
            { title: '数量', key: 'goodSkuNum', width: '200rpx', type: 'text', },
            { title: '旗舰店售卖价', key: 'goodSkuPrice', width: '200rpx', type: 'text', },
            { title: '天猫/京东链接', key: 'goodOnlineLink', width: '300rpx', type: 'copy-text', },
            { title: '图片', key: 'goodSkuPic', width: '200rpx', type: 'pic', },
          ]
        }
        if(this.data.orderMsg.fileType){
          let addColumns = [
            // { title: '单价', key: 'inputDiscountShow', width: '200rpx', type: 'input', },
            // { title: '折后单价', key: 'priceShow', width: '200rpx', type: 'input', },
          ]
          if(this.data.orderMsg.fileType == 2){
            goodColumns = addColumns.concat(this.data.fileType2Columns)
          }else if(this.data.orderMsg.fileType == 3){
            goodColumns = addColumns.concat(this.data.fileType3Columns)
          }
        }
        this.setData({
          goodColumns: goodColumns
        })
      }
      this.setData({
        chooseGoodDiscoutType: parseInt(val.detail.value),
        goodDiscount: null,
        goodList: list,
        goodTotalDiscount: 0,
      })
    }
  },

  bindDownloadExcel(){
    // 数据
    let data= this.data.channelGoodPriceList
    let sheet = []
    // 表头
      let title = ['商品名称', '商品规格', '单价', '商品数量', '总价']
      sheet.push(title)
      // 数据
      data.forEach(item => {
        let rowcontent = []
        rowcontent.push(item.goodName)
        rowcontent.push(item.skuName)
        rowcontent.push(item.price)
        rowcontent.push(item.num)
        rowcontent.push(item.totalPrice)
        sheet.push(rowcontent)
      })
  
      // XLSX插件使用
      var ws = XLSX.utils.aoa_to_sheet(sheet);
      var wb = XLSX.utils.book_new();
      XLSX.utils.book_append_sheet(wb, ws, "导出信息");
      var fileData = XLSX.write(wb, {
        bookType: "xlsx",
        type: 'base64'
      });
  
    // 保存的本地地址
      let filePath = `${wx.env.USER_DATA_PATH}/导出信息.xlsx`
  
      // 写文件
      const fs = wx.getFileSystemManager()
      fs.writeFile({
        filePath: filePath,
        data: fileData,
        encoding: 'base64',
        success(res) {
          console.log(res)
          const sysInfo = wx.getSystemInfoSync()
          // 导出
          if (sysInfo.platform.toLowerCase().indexOf('windows') >= 0) {
            // 电脑PC端导出
            wx.saveFileToDisk({
              filePath: filePath,
              success(res) {
                console.log(res)
              },
              fail(res) {
                console.error(res)
                util.tips("导出失败")
              }
            })
          } else {
            // 手机端导出
            // 打开文档
            wx.openDocument({
              filePath: filePath,
              showMenu:true,
              success: function (res) {
                console.log('打开文档成功')
              },
              fail: console.error
            })
          }
  
        },
        fail(res) {
  
          console.error(res)
          if (res.errMsg.indexOf('locked')) {
            wx.showModal({
              title: '提示',
              content: '文档已打开，请先关闭',
            })
          }
  
        }
      })
  },

  bindblurCheckRemark(e){
    let checkMsg = this.data.checkMsg
    checkMsg.remark = e.detail.value
    this.setData({
      checkMsg: checkMsg
    })
  },
//成本
  bindblurCheckCostPrice(e){
    let checkMsg = this.data.checkMsg
    checkMsg.costPrice =  e.detail.value
    if (this.data.costDiscountType == 1)
    checkMsg.finalCosthPrice = this.preciseMultiply(this.data.orderMsg.totalPrice, Number(e.detail.value) / 10)
    this.setData({
      checkMsg: checkMsg
    })
  },
//变现
  bindblurCheckCashPrice(e){
    let checkMsg = this.data.checkMsg
    checkMsg.cashPrice = e.detail.value
    if (this.data.cashDiscountType == 1){
      checkMsg.finalCashPrice = this.preciseMultiply(this.data.orderMsg.totalPrice, Number(e.detail.value) / 10)
    }
    if (this.data.cashDiscountType == 2){
      let cashDiscount = (Number(e.detail.value) / this.data.orderMsg.totalPrice * 10).toFixed(2)
      this.setData({
        cashDiscount: cashDiscount
      })
    }
    this.setData({
      checkMsg: checkMsg
    })
  },

  goShowSubmitSecond(){
    let data = this.data.orderMsg
    data.isSubmitBiddingSecondSubmit = false
    this.setData({
      orderMsg: data,
      goodDiscount: null,
    })
  },

  goShowSubmitFirst(){
    let data = this.data.orderMsg
    data.isSubmitBiddingFirstSubmit = false
    this.setData({
      orderMsg: data,
      goodDiscount: null,
    })
  },

  goShowSubmit(){
    this.setData({
      showSubmitCommitButton: true,
    })
  },
  
  goSetRate(){
    this.getSysList()
    this.setData({
      showType: 11,
      chooseSetRateId: this.data.orderMsg.rateId
    })
  },
  changeSetRate(e){
    this.setData({
      chooseSetRateId: Number(e.detail.value)
    })
  },
  //评级提交
  optionSetRate() {
    let params = {
      orderId: this.data.orderId,
      rateId: this.data.chooseSetRateId
    }
    server.post("/app/user/doSetAppOrderRate", params).then(res => {
      if (res.key === 1000) {
        this.getOrderMsg()
        wx.showToast({
          title: '提交成功',
          icon: 'success',
          duration: 2000
        })
      }
    });
    wx.hideLoading()
  },
  getSysList() {
    let params = {
      sysLabelIds: "44"
    }
    wx.showLoading({
      title: '加载中',
      mask: true,
    })
    server.post("/app/user/getSysLabelValueManageList", params).then(res => {
      if (res.key === 1000) {
        let data = res.result.data
        let setRateList = data[44]
        this.setData({
          setRateList: setRateList,
        })
      }
    });
    wx.hideLoading()
  },
  goPushFirstBidding(){
    this.getUserList(1,1, 2)
    this.setData({
      pushBiddingType: 2,
    })
  },
  // 开拓者设置第一次竞价截止时间
  goSetBiddingEndTime(){
    this.setData({
      showType: 5
    })
  },
  bindDateChange(e) {
    const { value: val } = e.detail;
    const year = new Date().getFullYear();
    const month = new Date().getMonth() + 1;
    const date = new Date().getDate();
    const year1 = new Date(val).getFullYear();
    const month1 = new Date(val).getMonth() + 1;
    const date1 = new Date(val).getDate();
    let showHour = "00";
    let showMin = "00";
    if (year === year1 && month === month1 && date === date1) {
      const hour = new Date().getHours();
      const min = new Date().getMinutes();
      const addHour = min + 30 >= 60 ? 1 : 0;
      const min1 = (min + 30) % 60;
      showMin = min1 < 10 ? `0${min1}` : min1.toString();
      let b = hour;
      if (addHour === 1) {
        b = hour + 1
      }
      showHour = b < 10 ? `0${b}` : b < 24 ? b.toString() : "00";
    }
    const time = `${showHour}:${showMin}`;
    this.setData({
      date: val,
      time,
      showHour,
      showMin,
      endTime: `${val} ${time}`,
      startTimeString: time,
    });
  },
  bindTimeChange(e){
    this.setData({
      time: e.detail.value
    })
  },
  sureSendEndTime(){
    if(this.data.date == '点击选择日期' || this.data.time == '点击选择时间'){
      return
    }
    if(!this.data.discountPrice){
      return
    }
    let time = this.data.date + " " + this.data.time
    let params = {
      orderId: this.data.orderId,
      endTime: new Date(time).getTime(),
      isDiscount: this.data.discountIndex == 0 ? 1 : 2,
      discountPrice: this.data.discountPrice
    }
    wx.showLoading({
      title: '加载中',
      mask: true,
    })
    if(this.data.orderMsg.biddingOneEndTime){
      server.post("/app/user/updateSureBiddingEndTime", params).then(res => {
        if (res.key === 1000) {
          this.getOrderMsg()
          wx.showToast({
            title: '提交成功',
            icon: 'success',
            duration: 2000
          })
        }
      });
    }else{
      server.post("/app/user/sureBiddingEndTime", params).then(res => {
        if (res.key === 1000) {
          this.getOrderMsg()
          wx.showToast({
            title: '提交成功',
            icon: 'success',
            duration: 2000
          })
        }
      });
    }
    wx.hideLoading()
  },

  // 开拓者打开渠道核价的商品列表
  showChannelGoodPriceList(e){
    let index = e.currentTarget.dataset.index
    let list = this.data.orderMsg.channelUserGoodListDTOS[index].goodPriceLists
    list.forEach(item => {
      item.totalPrice = (item.price * item.num).toFixed(2)
    })
    this.setData({
      showType: 4,
      channelGoodPriceList: list
    })
  },

  // 开拓者确认核价前输入的内容
  sureChannelPrice(e){
    const isAssistant = this.data.userInfo.userType == 2 && this.data.userInfo.isAssistant == 2
    const isTrailblazer = this.data.userInfo.userType == 2 && this.data.userInfo.isAssistant == 1
    if (isAssistant) this.getUserList(1, 1, 1, 'feedback')
    const showType = e.currentTarget.dataset.follow_up_submit// submit  feedback
    let checkMsg = this.data.checkMsg
    if ((showType == 'submit' || showType == 'feedback') && isTrailblazer) {
      const { channelUserGoodListDTOS, assistantCheckList } = this.data.orderMsg
      const noChannelUserGoodListDTOS = channelUserGoodListDTOS == null || (Array.isArray(channelUserGoodListDTOS) && channelUserGoodListDTOS.length == 0)
      const noAssistantCheckList = assistantCheckList == null || (Array.isArray(assistantCheckList) && assistantCheckList == 0)
      let arr1 = []
      let arr2 = []
      !noChannelUserGoodListDTOS && (() => { arr1 = channelUserGoodListDTOS.map(order => Number(order.totalPrice)) })()
      !noAssistantCheckList && (() => { arr2 = assistantCheckList.map(order => Number(order.checkCashPrice)) })()
      const maxPrice = Math.max(...arr1, ...arr2)
      checkMsg.cashPrice = maxPrice
    }
    this.getSysList()
    this.setData({
      showType: 6,
      checkMsg: checkMsg,
      chooseSetRateId: null,
    })
  },
  // 开拓者确认核价
  sureChannelPriceSecond(){
    this.setData({
      confirmLoading: true
    })
    let that = this
    setTimeout(()=>{
      that.sureChannelPriceThird()
    },1000)
  },
  sureChannelPriceThird(){
    const isAssistant = this.data.userInfo.userType == 2 && this.data.userInfo.isAssistant == 2
    if(!this.data.checkMsg.remark && !isAssistant){
      wx.showToast({
        title: '请输入备注',
        icon: 'error',
        duration: 2000
      })
      this.setData({
        confirmLoading: false
      })
      return
    }else if(!this.data.checkMsg.costPrice && !isAssistant){
      wx.showToast({
        title: '请输入建议成本',
        icon: 'error',
        duration: 2000
      })
      this.setData({
        confirmLoading: false
      })
      return
    }else if(!this.data.checkMsg.cashPrice){
      wx.showToast({
        title: '请输入变现价格',
        icon: 'error',
        duration: 2000
      })
      this.setData({
        confirmLoading: false
      })
      return
    }
    // let params = {
    //   orderId: this.data.orderId,
    //   remark: this.data.checkMsg.remark,
    //   costPrice: this.data.checkMsg.costPrice,
    //   cashPrice: this.data.checkMsg.cashPrice,
    // }
    const params2 = {
      cashDiscountType: this.data.cashDiscountType,
      checkCashPrice: this.data.checkMsg.cashPrice,//变现价格 cashDiscountType为1 该值表示折扣，为2表示金额
      checkRemark: this.data.checkMsg.remark,
      costDiscountType: this.data.costDiscountType,
      checkCostPrice: this.data.checkMsg.costPrice,//建议成本 同理
      orderId: this.data.orderMsg.id
    }
    if(this.data.chooseSetRateId){
      params2.chooseSetRateId = this.data.chooseSetRateId
    }
    const params = {...params2}
    if (isAssistant) {
      params.channelIds = this.data.channelIds
      delete params.checkRemark
      delete params.costDiscountType
      delete params.checkCostPrice
    }
    wx.showLoading({
      title: '加载中',
      mask: true,
    })
    server.post("/app/user/sureChannelCheckPrice", params).then(res => {
      if (res.key === 1000) {
        this.setData({
          confirmLoading: false
        })
        this.getOrderMsg()
        wx.showToast({
          title: '提交成功',
          icon: 'success',
          duration: 3000
        })
      }
    });
    this.setData({
      confirmLoading: false
    })
    wx.hideLoading()
  },
  chooseSetRateIdByChannelRadioChange(e) {
    const chooseSetRateId = e.detail.value
    this.setData({
      chooseSetRateId: chooseSetRateId
    })
  },
  chooseAssistantByChannelRadioChange(e) {
    const channelIds = e.detail.value
    this.setData({
      channelIds: channelIds
    })
  },
  submitOptionChange(e) {
    const cashDiscountTypeValue = this.data.cashDiscountTypeArr.find(item => item.id == Number(e.detail.value) + 1)
    const newValue = this.data.checkMsg
    newValue.cashPrice = null
    this.setData({
      cashDiscountType: cashDiscountTypeValue.id,
      currentCashDiscountTypeIndex: Number(e.detail.value),
      checkMsg: newValue
    })
  },
  submitOptionChange2(e) {
    const costDiscountTypeValue = this.data.costDiscountTypeArr.find(item => item.id == Number(e.detail.value) + 1)
    const newValue = this.data.checkMsg
    newValue.costPrice = null
    this.setData({
      costDiscountType: costDiscountTypeValue.id,
      currentCostDiscountTypeIndex: Number(e.detail.value),
      checkMsg: newValue
    })
  },
  submitGoodPrice(){
    let goodList = []
    let hasAdd = false
    this.data.goodList.forEach(item => {
      if(!item.inputDiscount || item.inputDiscount == 0){
        hasAdd = true
      }
      goodList.push({
        goodId: item.id,
        skuId: item.goodSkuId,
        price: this.data.chooseGoodDiscoutType == 1 ? (((item.goodSkuPrice || (!item.goodSkuPrice && item.goodSkuPrice == 0)) ? item.goodSkuPrice : item.price) * (item.inputDiscount / 10)) : item.inputDiscount,
        num: (item.goodSkuNum ? item.goodSkuNum : 0),
        discountPrice: this.data.chooseGoodDiscoutType == 1 ? (((item.goodSkuPrice || (!item.goodSkuPrice && item.goodSkuPrice == 0)) ? item.goodSkuPrice : item.price) * (item.inputDiscount / 10)) : item.inputDiscount,
      })
    })
    if(hasAdd && this.data.chooseGoodDiscoutType == 1){
      wx.showToast({
        title: '请填写全部单价',
        icon: "fail"
      })
      return
    }
    if(this.data.chooseGoodDiscoutType == 2 && !this.data.goodDiscount){
      wx.showToast({
        title: '请填写全部单价',
        icon: "fail"
      })
      return
    }
    if(this.data.goodDiscount && this.data.chooseGoodDiscoutType == 1 && this.data.goodDiscount > 10){
      wx.showToast({
        title: '不能大于10',
        icon: "error"
      })
      return
    }
    let params = {
      orderId: this.data.orderId,
      orderType: this.data.orderMsg.status == 4 ? 2 : this.data.orderMsg.status == 5 ? 3 : 1,
      discountType: this.data.chooseGoodDiscoutType,
      goods: JSON.stringify(goodList)
    }
    wx.showLoading({
      title: '加载中',
      mask: true,
    })
    server.post("/app/user/channelCheckPrice", params).then(res => {
      if (res.key === 1000) {
        this.getOrderMsg()
        this.setData({
          submitCommitButton: '修改',
          showSubmitCommitButton: false,
        })
        wx.showToast({
          title: '提交成功',
          icon: 'success',
          duration: 2000
        })
      }
    });
    wx.hideLoading()
  },

  bindblurGoodTotalPrice(e){
    if(this.data.inputPricePercent == 100){
      return
    }
    if(e.detail.value == '0.00' || e.detail.value == '0'){
      return
    }
    let totalPrice = e.detail.value
    let goodList = this.data.goodList
    let hasPrice = 0  //已添加金额的总金额数
    let needNum = 0 //没有添加金额的剩余总数
    goodList.forEach(item => {
      if(item.inputPrice && item.inputPrice != 0){
        hasPrice = hasPrice + (item.inputPrice * (item.goodSkuNum ? item.goodSkuNum : item.num))
      }else{
        needNum = needNum + (item.goodSkuNum ? item.goodSkuNum : item.num)
      }
    })
    let onePrice = (totalPrice - hasPrice) / needNum
    goodList.forEach(item => {
      if(!item.inputPrice || item.inputPrice == 0){
        item.inputPrice = onePrice.toFixed(2)
      }
    })
    this.setData({
      totalPrice: totalPrice.toFixed(2),
      goodList: goodList,
      inputPricePercent: 100,
    })
  },

  updatePricePercent(){
    let goodList = this.data.goodList
    let inputNum = 0
    goodList.forEach(item => {
      if(item.inputPrice && item.inputPrice != 0){
        inputNum+= 1
      }
    })
    let p = inputNum/goodList.length * 100
    if(p > 100){
      p = 100
    }
    this.updateTotalPrice()
    this.setData({
      inputPricePercent: parseInt(p)
    })
  },
  bindblurGoodInputPrice(e){
    if(e.detail.value == '0.00' || e.detail.value == '0'){
      return
    }
    let price = e.detail.value
    let goodList = this.data.goodList
    goodList[this.data.showGoodMsgIndex].inputPrice = price
    this.setData({
      goodList: goodList
    })
    this.updatePricePercent()
  },
  bindShowPrev(){
    if(!this.data.showGoodMsgIndex || this.data.showGoodMsgIndex == 0){
      return
    }else{
      this.setData({
        showGoodMsgIndex: (this.data.showGoodMsgIndex - 1) < 0 ? 0 : (this.data.showGoodMsgIndex - 1)
      })
    }
  },
  bindShowNext(){
    let that = this
    if(this.data.showGoodMsgIndex >= (this.data.goodList.length - 1)){
      return
    }
    setTimeout(()=>{
      that.setData({
        showGoodMsgIndex: that.data.showGoodMsgIndex + 1
      })
    },100)
  },

  closePopup(){
    this.setData({
      showType: null,
    })
  },
  getUserList(userType,showType,controlType,btnType = '') {
    let params = {
      orderId: this.data.orderId
    }
    if(userType){
      params.userType = userType
    }
    if(showType == 1){
      params.pushUserIds = this.data.userInfo.userId
    }
    if(showType == 2){
      let userIds = this.data.userInfo.userId
      if(this.data.orderMsg.transferUserIds){
        userIds = userIds + ',' + this.data.orderMsg.transferUserIds
      }
      params.notInUserIds = userIds
    }
    wx.showLoading({
      title: '加载中',
      mask: true,
    })
    server.post("/app/user/userAppList", params).then(res => {
      if (res.key === 1000) {
        let selectUserList = []
        res.result.list.forEach(item => {
          item.checked = null
          if(controlType && controlType == 1 && this.data.orderMsg.pushChannelUserIds){
            this.data.orderMsg.pushChannelUserIds.split(",").forEach(pushUserItem => {
              if(parseInt(pushUserItem) == item.id){
                item.checked = 1
              }
            })
          }
          if(controlType && controlType == 2 && this.data.orderMsg.biddingPushChannelUserIds){
            this.data.orderMsg.biddingPushChannelUserIds.split(",").forEach(pushUserItem => {
              if(parseInt(pushUserItem) == item.id){
                item.checked = 1
              }
            })
          }
          selectUserList.push(item)
        })
        if(showType == 2){
          if(res.result.list && res.result.list.length <= 0){
            wx.showToast({
              title: '已无开拓者可选',
              icon: 'error',
              duration: 2000
            })
          }
        }
        var userMap = new Map();
        selectUserList.forEach(item => {
          if(item.isAssistant == 2){
            item.assistantUserIds.split(",").forEach(subItem => {
              if(userMap.get(subItem + "")){
                userMap.get(subItem + "").push(item)
              }else{
                userMap.set(subItem, [item])
              }
            })
          }
        })
        selectUserList.forEach(item => {
          if(userMap.get(item.id + "")){
            item.subUserList = userMap.get(item.id + "")
          }
        })
        const isAssistant = this.data.userInfo.userType == 2 && this.data.userInfo.isAssistant == 2
        if (isAssistant && btnType == 'feedback') {
          this.setData({
            selectUserList: selectUserList,
          })
        } else {
          this.setData({
            selectUserList: selectUserList,
            showType: showType,
          })
        }
      }
    });
    wx.hideLoading()
  },

  // 文件路径过滤【文件名+.后缀名】
  // 例如：哈哈.pdf
  getFilePathName(path) {
    let pos1 = path.lastIndexOf('/');
    let pos2 = path.lastIndexOf('\\');
    let position  = Math.max(pos1, pos2);
    if ( position< 0 )
      return path;
    else
      return path.substring(position+ 1);
  },
  
  //下载表单
  goDownload(){
    let that = this
    let FileSystemManager = wx.getFileSystemManager()
    let params = {
      orderId: this.data.orderId
    }
    wx.showLoading({
      title: '文件打开中',
      mask: true,
    })
    server.post("/app/user/doDownloadFile", params).then(resResult => {
      if (resResult.key === 1000) {
        let data = resResult.result.data
            wx.downloadFile({
              url: data.path,
              // 1. 必须带有这个wx.env.USER_DATA_PATH，表示存储在用户本地 ！！！
              // fileName表示自定的文件名称
              // 实际在PC端调试存储位置为类似 C:\Users\SJshe\AppData\Local\微信开发者工具\User Data\WeappFileSystem\o6zAJs3c0u3SeBVn_9MUgG6UZJ1M\wx2efdf4edd8bccb88
              success: function (res) {
                if (res.statusCode === 200) {
                  let filePath = res.tempFilePath
                  that.setData({
                    filePath: res.tempFilePath
                  })
                  FileSystemManager.saveFile({
                    tempFilePath: filePath,
                    success: function(savedFilePathRes) {          
                      wx.openDocument({
                        filePath: savedFilePathRes.savedFilePath,
                        showMenu:true,
                        fileType: 'xlsx', // 2. 这个必须写合法类型，不然下载不了(个人认为官方应该特别说明) ！！！
                        success: function(res) {
                          console.log('打开文档成功')
                          wx.hideLoading()
                        },
                        fail: function(e) {
                          console.log(e.errMsg);
                        }
                      })
                    },
                    fail: function(failResult) {
                      console.log("失败原因===》",failResult)
                    }
                  })
                }
              },
              fail: function(e) { // 强烈建议打印失败原因，便于排查
                console.log(e.errMsg);
              }
            });
      }
    });

  },
  downloadFile(){
    let that = this
    let params = {
      orderId: this.data.orderId
    }
    wx.showLoading({
      title: '加载中',
      mask: true,
    })
    server.post("/app/user/doDownloadFile", params).then(resResult => {
      if (resResult.key === 1000) {
        let data = resResult.result.data
        let path = data.path
        let orderMsg = that.data.orderMsg
        orderMsg.pathUrls = path
        this.setData({
          orderMsg: orderMsg
        })
      }
    });
    wx.hideLoading()

  },
  //分享表单
  goDownloadShare(){
    let that = this
    let params = {
      orderId: this.data.orderId
    }
    wx.showLoading({
      title: '加载中',
      mask: true,
    })
    server.post("/app/user/doDownloadFile", params).then(resResult => {
      if (resResult.key === 1000) {
        let data = resResult.result.data
        let path = data.path
        let orderMsg = that.data.orderMsg
        orderMsg.pathUrls = path
        that.setData({
          orderMsg: orderMsg
        })
        wx.downloadFile({
          url: that.data.orderMsg.pathUrls,
          // 1. 必须带有这个wx.env.USER_DATA_PATH，表示存储在用户本地 ！！！
          // fileName表示自定的文件名称
          // 实际在PC端调试存储位置为类似 C:\Users\SJshe\AppData\Local\微信开发者工具\User Data\WeappFileSystem\o6zAJs3c0u3SeBVn_9MUgG6UZJ1M\wx2efdf4edd8bccb88
          success: function (res) {
            if (res.statusCode === 200) {
              let pathFile = that.data.orderMsg.pathUrls.split(".")[that.data.orderMsg.pathUrls.split(".").length - 1]
              // 编辑转发文档
              wx.shareFileMessage({
                filePath: res.tempFilePath,
                fileName: that.data.orderMsg.brands + "." + pathFile,
                success: function(res) {
                  console.log('分享成功',res)
                },
                fail: function(res) {
                  console.log("分享失败",res)
                }
              })
            }
            wx.hideLoading()
          },
          fail: function(e) { // 强烈建议打印失败原因，便于排查
            console.log(e.errMsg);
          }
        });
      }
    });
  },
  // 去分配
  goPush(){
    this.getUserList(1,1, 1)
  },
  checkBoxUser(chooseUserList, chooseZhuliUserList){
    let zhuliList = []
    let selectUserList = this.data.selectUserList
    selectUserList.forEach(item => {
      item.checked = false
      if(item.subUserList && item.subUserList.length > 0){
        item.checked = false
      }
    })
    //循环判断勾选的人
    chooseUserList.forEach(id => {
      selectUserList.forEach(item => {
        if(item.id == id){
          item.checked = true
          if(item.isAssistant == 1 && item.subUserList && item.subUserList.length > 0){
            item.subUserList.forEach(subItem => {
              chooseZhuliUserList.forEach(chooseItem => {
                if(subItem.id == chooseItem){
                  subItem.checked = true
                }
              })
              zhuliList.push(subItem)
            })
          }
        }
      })
    })
    //去重
    zhuliList = [...new Set(zhuliList)]
    this.setData({
      zhuliList: zhuliList,
      chooseUserList: chooseUserList,
      chooseZhuliUserList: chooseZhuliUserList,
      selectUserList: selectUserList,
    })
  },
  checkboxChangeUser2(e){
    let chooseZhuliUserList = e.detail.value
    this.checkBoxUser(this.data.chooseUserList, chooseZhuliUserList)
  },
  checkboxChangeUser1(e){
    let chooseUserList = e.detail.value
    this.checkBoxUser(chooseUserList, this.data.chooseZhuliUserList)
  },
  sureCheckChange(){
    let hasUsers = []
    if(!this.data.chooseUserList || this.data.chooseUserList.length <= 0){
      if(this.data.selectUserList && this.data.selectUserList.length > 0){
        this.data.selectUserList.forEach(item => {
          if(item.checked == 1){
            hasUsers.push(item.id)
          }
        })
      }
    }else{
      this.data.chooseUserList.forEach(item => {
        hasUsers.push(item)
      })
    }
    if(hasUsers && hasUsers.length > 0){
      this.checkChannelMsg(hasUsers.join(","))
    }else{
      wx.showToast({
        title: '请选择人员',
        icon: 'error',
        duration: 2000
      })
      return
    }
  },
  checkChannelMsg(userIds) {
    let params = {
      orderId: this.data.orderId,
      userIds: userIds
    }
    wx.showLoading({
      title: '加载中',
      mask: true,
    })
    if(this.data.pushBiddingType == 2){
      server.post("/app/user/surePushChannelUser", params).then(res => {
        if (res.key === 1000) {
          this.setData({
            showType: null
          })
          this.getOrderMsg()
          wx.showToast({
            title: '分配成功',
            icon: 'success',
            duration: 2000
          })
        }
      });
    }else{
      server.post("/app/user/checkChannelMsg", params).then(res => {
        if (res.key === 1000) {
          this.setData({
            showType: null
          })
          this.getOrderMsg()
          wx.showToast({
            title: '分配成功',
            icon: 'success',
            duration: 2000
          })
        }
      });
    }
    wx.hideLoading()
  },
  // 转移
  goSend(){
    this.getUserList(2,2)
  },
  sureTransferChange(){
    let hasUsers = []
    //判断是否为空并且选择人员列表都在selectUserList里
    if(!this.data.chooseUserList || this.data.chooseUserList.length <= 0){
      wx.showToast({
        title: '请选择人员',
        icon: 'error',
        duration: 2000
      })
    }else{
      this.data.selectUserList.forEach(item => {
        if(item.isAssistant == 1){
          if(item.checked){
            hasUsers.push(item.id)
            if(item.subUserList && item.subUserList.length > 0){
              item.subUserList.forEach(subItem => {
                if(subItem.checked){
                  hasUsers.push(subItem.id)
                }
              })
            }
          }
        }
      })
    }
    if(hasUsers && hasUsers.length > 0){
      this.transferPushUsers(hasUsers.join(","))
    }else{
      wx.showToast({
        title: '请选择人员',
        icon: 'error',
        duration: 2000
      })
    }
    this.setData({
      zhuliList: []
    })
  },
  transferPushUsers(userIds) {
    let params = {
      orderId: this.data.orderId,
      userIds: userIds
    }
    wx.showLoading({
      title: '加载中',
      mask: true,
    })
    server.post("/app/user/transferPushUsers", params).then(res => {
      if (res.key === 1000) {
        this.setData({
          showType: null
        })
        this.getOrderMsg()
        wx.showToast({
          title: '转移成功',
          icon: 'success',
          duration: 2000
        })
      }
    });
    wx.hideLoading()
  },
  handleBlindBoxItemChange(e){
    let val = e.detail.detail.value
    let index = e.detail.currentTarget.dataset.index
    let goodList = this.data.chooseGoodList
    goodList[index].num = val
    this.setData({
      chooseGoodList: goodList,
    })
  },
  // 盲盒竞价
  goBlindBox(){
    let goodList = []
    let goodTitle = [
      { title: '品牌', key: 'brandsValue', width: '300rpx', type: 'text', },
      { title: '商品名称', key: 'goodName', width: '300rpx', type: 'text', },
      { title: '规格', key: 'goodSku', width: '200rpx', type: 'text', },
      { title: '数量', key: 'totalNum', width: '150rpx', type: 'text', },
      { title: '拿取数量', key: 'num', width: '200rpx', type: 'input', },
    ]
    this.data.goodList.forEach(goodItem => {
      goodList.push({
        goodId: goodItem.id,
        skuId: goodItem.goodSkuId,
        num: goodItem.goodSkuNum ? item.goodSkuNum : item.num,
        totalNum: goodItem.goodSkuNum ? item.goodSkuNum : item.num,
        goodName: goodItem.goodName,
        goodSku: goodItem.goodSku,
      })
    })
    this.setData({
      showType: 3,
      chooseGoodList: goodList,
      chooseGoodTitle: goodTitle,
    })
  },
  switchChangeTaskAll(e){
    let list = this.data.chooseGoodList
    list.forEach(item => {
      item.num = item.totalNum
    })
    this.setData({
      chooseGoodList: list,
      taskAllType: e.detail.value,
    })
  },
  bindblurBoxPrice(e){
    this.setData({
      blindBoxPrice: e.detail.value
    })
  },
  sureBlindBox(){
    if(!this.data.blindBoxPrice){
      wx.showToast({
        title: '请输入金额',
        icon: 'error',
        duration: 2000
      })
    }
    let params = {
      orderId: this.data.orderId,
      blindBoxPrice: this.data.blindBoxPrice,
      takeAllStatus: this.data.taskAllType ? 2 : 1,
      goods: JSON.stringify(this.data.chooseGoodList)
    }
    wx.showLoading({
      title: '加载中',
      mask: true,
    })
    server.post("/app/user/blindBoxRate", params).then(res => {
      if (res.key === 1000) {
        this.setData({
          showType: null,
        })
        this.getOrderMsg()
        wx.showToast({
          title: '盲盒配包成功',
          icon: 'success',
          duration: 2000
        })
      }
    });
    wx.hideLoading()
  },
  getStatusName(item){
    let userInfo = this.data.userInfo
    let userId = userInfo.userId
    let statusMap = wx.getStorageSync('statusMap')
    let statusName = ''
    if(userInfo.userType == 1){
      // 渠道商的订单状态
      if(item.status == 2){
        // 未提交核价
        statusName = statusMap[71]
        // 已提交核价并且用户id是自己的，才判断为已提交
        if(item.submitCheckUserIds){
          let a = ',' + item.submitCheckUserIds + ','
          let b = ',' + userId + ','
          if(item.isSubmitCheck && item.isSubmitCheck == 2 && a.indexOf(b) > -1){
            statusName = statusMap[72]
          }
        }
        // 判断是否为重新推送的订单
        if(item.isBackPush && item.isBackPush == 2){
          statusName = statusMap[73]
          if(item.submitCheckUserIds){
            let a = ',' + item.submitCheckUserIds + ','
            let b = ',' + userId + ','
            if(a.indexOf(b) > -1){
              statusName = statusMap[72]
            }else{
              statusName = statusMap[71]
            }
          }
        }
      } else if(item.status == 3){
        statusName = statusMap[72]
        // 未提交核价
        // statusName = statusMap[71]
        // 已提交核价并且用户id是自己的，才判断为已提交
        if(item.submitCheckUserIds){
          let a = ',' + item.submitCheckUserIds + ','
          let b = ',' + userId + ','
          if(item.isSubmitCheck && item.isSubmitCheck == 2 && a.indexOf(b) > -1){
            statusName = statusMap[72]
          }
        }
      } else if(item.status == 4){
        // 没有设定截止时间，展示等消息
        if(!item.biddingOneEndTime){
          statusName = statusMap[72]
        }else{
          // 开拓者没有分配渠道或者没有分配该渠道，展示等消息
          if(!item.biddingPushChannelUserIds){
            statusName = statusMap[72]
          }else{
            let a = ',' + item.biddingPushChannelUserIds + ','
            let b = ',' + userId + ','
            if(a.indexOf(b) > -1){
              let c = ',' + item.biddingFirstUserIds + ','
              if(c.indexOf(b) > -1){
                statusName = statusMap[75]
              }else{
                statusName = statusMap[74]
              }
            }else{
              statusName = statusMap[72]
            }
          }
        }
      } else if(item.status == 5){
        statusName = statusMap[75]
        if(item.biddingStartTwo && item.biddingStartTwo == 2){
          let a = ',' + item.biddingSecondUserIds + ','
          let b = ',' + userId + ','
          if(a.indexOf(b) > -1){
            statusName = statusMap[77]
          }else{
            statusName = statusMap[76]
          }
        }
        if(!item.channelFirstRank){
          statusName = '您无权利参与第二次竞价阶段'
        }
      } else if(item.status == 7){
        statusName = statusMap[78]
        if(item.lastUserId && item.lastUserId == this.data.userInfo.userId){
          statusName = statusMap[93]
        }
        if(item.lastUserId && item.lastUserId != this.data.userInfo.userId){
          statusName = statusMap[92]
        }
      } else if(item.status == 8){
        statusName = statusMap[90]
      }
      if (item.channelRefuseIds && (',' + item.channelRefuseIds + ',').indexOf(',' + this.data.userInfo.userId + ',') > -1){
        statusName = statusMap[94]
      }
      if(item.isNextPush == 2 && item.pushUserIds && ((',' + item.pushUserIds + ',').indexOf(',' + this.data.userInfo.userId + ',') > -1)){
        // statusName += '，您没有权利参与竞价'
      }
      if(userInfo.touristType && userInfo.touristType == 2){
        statusName = "您当前为访客模式，不支持核价/报价"
      }
    }else if(userInfo.userType == 2){
      // 开拓者的订单状态
      if(item.status == 1){
        statusName = statusMap[79]
      } else if(item.status == 2){
        // 未收到核价的时候
        statusName = statusMap[80]
        // 判断是否为发布者重新推送的订单
        if(item.isBackPush && item.isBackPush == 2){
          statusName = statusMap[83]
        }
        //  已收到任一渠道商提交的核价
        if(item.isSubmitCheck && item.isSubmitCheck == 2){
          statusName = statusMap[81]
        }
      } else if(item.status == 3){
        statusName = statusMap[82]
        // if(item.isSubmitCheck && item.isSubmitCheck == 2){
        //   statusName = statusMap[81]
        // }
      } else if(item.status == 4){
        if(!item.biddingOneEndTime){
          statusName = statusMap[85]
        }else{
          statusName = statusMap[86]
        }
      } else if(item.status == 5){
        statusName = statusMap[87]
      } else if(item.status == 8){
        statusName = statusMap[90] + (item.refuseReason ? ('-' + item.refuseReason) : '')
      } else {
        statusName = statusMap[88]
      }
      if(item.isNextPush == 2 && item.pushUserIds && ((',' + item.pushUserIds + ',').indexOf(',' + this.data.userInfo.userId + ',') > -1)){
        statusName = '已转移，' + statusName
      }
      if(item.pushChannelUserIds && item.pushChannelUserIds.trim() && item.isSubmitCheck != 2){
        statusName = statusName + '，新订单' 
      }
      if(item.projectStatus == 9){
        statusName = statusMap[88] + "，已黄单"
      }
    }else{
      // 其他
      statusName = '未知'
    }
    return statusName;
  },
  getOrderMsg() {
    let that = this
    let params = {
      orderId: this.data.orderId
    }
    wx.showLoading({
      title: '加载中',
      mask: true,
    })
    server.post("/app/user/getOrderMsg", params).then(res => {
      if (res.key === 1000) {
        let inputPricePercent = 0
        let totalPrice = 0
        let showTitle = ''
        let data = res.result.data
        let tableData = []
        let goodList = []
        let endTime = ''
        let endTimeString = ''
        let submitCommitButton = '提交'
        let showSubmitCommitButton = false
        let chooseUserList = []
        let goodTotalDiscount = 0
        let goodTotalDiscount2 = 0
        let hasJoinBidding = 1
        let hasAddJoinBidding = 1
        let leftTime = 0
        let finalRealPrice = 0
        data.isSubmitBiddingSecondSubmit = data.isSubmitBiddingSecond
        data.goodList.forEach(item => {
          item.inputPrice = null
          item.inputDiscount = null
          item.inputDiscountShow = null
          let itemFinalRealPrice = 0
          let num = item.num
          if(item.goodSkuNum){
            num = item.goodSkuNum
          }
          let finalPrice = 0
          if (item.realPrice){
            finalPrice = item.realPrice
          }
          if (item.finalPrice){
            finalPrice = item.finalPrice
          }
          item.finalPrice = finalPrice
          itemFinalRealPrice = finalPrice * num
          item.finalTotalPrice = itemFinalRealPrice
          finalRealPrice = finalRealPrice + itemFinalRealPrice
          tableData.push(item)
          goodList.push(item)
        })
        data.finalRealPrice = finalRealPrice
        data.checkMsgList && data.checkMsgList.forEach(checkMsg => {
          checkMsg.createDate = formatDateCN(new Date(checkMsg.createTime))
        })
        if(this.data.userInfo.userType == 1){
          if(data.goodPriceLists && data.goodPriceLists.length > 0){
            inputPricePercent = 100
            goodList.forEach(item => {
              data.goodPriceLists.forEach(goodItem => {
                if(item.id == goodItem.goodId && item.goodSkuId == goodItem.skuId){
                  item.inputPrice = null
                  item.inputDiscount = null
                  item.inputDiscountShow = null
                  totalPrice = totalPrice + ((item.goodSkuPrice || (!item.goodSkuPrice && item.goodSkuPrice == 0)) ? item.goodSkuPrice : item.price) * goodItem.num
                  goodTotalDiscount2 = goodTotalDiscount2 + goodItem.price * goodItem.num
                }
              })
            })
          }
        }
        let columns = [
          { title: '品牌', key: 'brandsValue', width: '300rpx', type: 'text', },
          { title: '商品名称', key: 'goodName', width: '300rpx', type: 'text', },
          { title: '有效期至', key: 'goodExpirationDate', width: '200rpx', type: 'text', },
          { title: '保质期', key: 'goodWarrantyDate', width: '200rpx', type: 'text', },
          { title: '规格', key: 'goodSku', width: '200rpx', type: 'text', },
          { title: '数量', key: 'goodSkuNum', width: '200rpx', type: 'text', },
          { title: '旗舰店售卖价', key: 'goodSkuPrice', width: '200rpx', type: 'text', },
          { title: '天猫/京东链接', key: 'goodOnlineLink', width: '300rpx', type: 'copy-text', },
          { title: '图片', key: 'goodSkuPic', width: '200rpx', type: 'pic', },
          { title: '箱规（数量）', key: 'goodBoxNum', width: '300rpx', type: 'text', },
          { title: '箱规（尺寸mm）', key: 'goodBoxSize', width: '300rpx', type: 'text', },
          { title: '单个产品包装尺寸mm', key: 'goodOneSize', width: '300rpx', type: 'text', },
          { title: '店铺粉丝量', key: 'shopFans', width: '300rpx', type: 'text', },
          { title: '产品销量', key: 'goodSaleNum', width: '300rpx', type: 'text', },
          { title: '实际成交价', key: 'finalPrice', width: '300rpx', type: 'text', },
          { title: '实际成交总价', key: 'finalTotalPrice', width: '300rpx', type: 'text', },
          { title: '旗舰店价格', key: 'flagshipstorePrice', width: '300rpx', type: 'text', },
          { title: '旗舰店粉丝量', key: 'flagshipstoreFans', width: '300rpx', type: 'text', },
          { title: '销量', key: 'salesNum', width: '300rpx', type: 'text', },
          { title: '评价', key: 'evaluateContent', width: '300rpx', type: 'text', },
          { title: '最低价', key: 'lowestPrice', width: '300rpx', type: 'text', },
          { title: '链接', key: 'link', width: '300rpx', type: 'text', }
        ]
        let goodColumns = [
          // { title: '折扣', key: 'inputDiscountShow', width: '200rpx', type: 'input', },
          // { title: '折后单价', key: 'priceShow', width: '200rpx', type: 'input', },
          { title: '品牌', key: 'brandsValue', width: '300rpx', type: 'text', },
          { title: '商品名称', key: 'goodName', width: '300rpx', type: 'text', },
          { title: '有效期至', key: 'goodExpirationDate', width: '200rpx', type: 'text', },
          { title: '保质期', key: 'goodWarrantyDate', width: '200rpx', type: 'text', },
          { title: '规格', key: 'goodSku', width: '200rpx', type: 'text', },
          { title: '数量', key: 'goodSkuNum', width: '200rpx', type: 'text', },
          { title: '旗舰店售卖价', key: 'goodSkuPrice', width: '200rpx', type: 'text', },
          { title: '天猫/京东链接', key: 'goodOnlineLink', width: '300rpx', type: 'copy-text', },
          { title: '图片', key: 'goodSkuPic', width: '200rpx', type: 'pic', },
          { title: '箱规（数量）', key: 'goodBoxNum', width: '300rpx', type: 'text', },
          { title: '箱规（尺寸mm）', key: 'goodBoxSize', width: '300rpx', type: 'text', },
          { title: '单个产品包装尺寸mm', key: 'goodOneSize', width: '300rpx', type: 'text', },
          { title: '店铺粉丝量', key: 'shopFans', width: '300rpx', type: 'text', },
          { title: '产品销量', key: 'goodSaleNum', width: '300rpx', type: 'text', },
          { title: '实际成交价', key: 'finalPrice', width: '300rpx', type: 'text', },
          { title: '实际成交总价', key: 'finalTotalPrice', width: '300rpx', type: 'text', },
          { title: '旗舰店价格', key: 'flagshipstorePrice', width: '300rpx', type: 'text', },
          { title: '旗舰店粉丝量', key: 'flagshipstoreFans', width: '300rpx', type: 'text', },
          { title: '销量', key: 'salesNum', width: '300rpx', type: 'text', },
          { title: '评价', key: 'evaluateContent', width: '300rpx', type: 'text', },
          { title: '最低价', key: 'lowestPrice', width: '300rpx', type: 'text', },
          { title: '链接', key: 'link', width: '300rpx', type: 'text', }
        ]
        if(this.data.userInfo && this.data.userInfo.userType == 1){
          columns = [
            { title: '品牌', key: 'brandsValue', width: '300rpx', type: 'text', },
            { title: '商品名称', key: 'goodName', width: '300rpx', type: 'text', },
            { title: '商品规格', key: 'goodSku', width: '300rpx', type: 'text', },
            { title: '有效期至', key: 'goodExpirationDate', width: '200rpx', type: 'text', },
            { title: '保质期', key: 'goodWarrantyDate', width: '200rpx', type: 'text', },
            { title: '数量', key: 'goodSkuNum', width: '200rpx', type: 'text', },
            { title: '旗舰店售卖价', key: 'goodSkuPrice', width: '200rpx', type: 'text', },
            { title: '天猫/京东链接', key: 'goodOnlineLink', width: '300rpx', type: 'copy-text', },
            { title: '图片', key: 'goodSkuPic', width: '200rpx', type: 'pic', },
          ]
          goodColumns = [
            // { title: '折扣', key: 'inputDiscountShow', width: '200rpx', type: 'input', },
            // { title: '折后单价', key: 'priceShow', width: '200rpx', type: 'input', },
            { title: '品牌', key: 'brandsValue', width: '300rpx', type: 'text', },
            { title: '商品名称', key: 'goodName', width: '300rpx', type: 'text', },
            { title: '有效期至', key: 'goodExpirationDate', width: '200rpx', type: 'text', },
            { title: '保质期', key: 'goodWarrantyDate', width: '200rpx', type: 'text', },
            { title: '规格', key: 'goodSku', width: '200rpx', type: 'text', },
            { title: '数量', key: 'goodSkuNum', width: '200rpx', type: 'text', },
            { title: '旗舰店售卖价', key: 'goodSkuPrice', width: '200rpx', type: 'text', },
            { title: '天猫/京东链接', key: 'goodOnlineLink', width: '300rpx', type: 'copy-text', },
            { title: '图片', key: 'goodSkuPic', width: '200rpx', type: 'pic', },
          ]
        }
        let checkedBlindBox = false
        if(data){
          checkedBlindBox = data.blindBoxAllTake == 2 ? true : false
        }
        if((data.status == 4 || data.status == 5) && data.biddingOneEndTime){
          let aTime = formatDateTimeCN(new Date(data.biddingOneEndTime))
          let timeLong = new Date(data.biddingOneEndTime).getTime()
          if(data.biddingTwoTimeSlot && data.status == 5){
            var a1 = data.biddingOneEndTime + data.biddingTwoTimeSlot * 60 * 60 * 1000
            aTime = formatDateTimeCN(new Date(a1))
            timeLong = new Date(a1).getTime()
          }
          endTimeString = aTime
          endTime = '截止时间：' + aTime
          let t = (timeLong - new Date().getTime())
          leftTime = (t / 1000).toFixed(0)
        }
        data.showBiddingType = false
        
        let hasPushButton = true
        if(this.data.userInfo.userType == 1){
          if(data.status == 2){
            showTitle = '请尽快核价'
            if(!data.isSubmitCheckPrice){
              showTitle = '核价确认等待中'
              submitCommitButton = '修改'
            }
            if(!data.goodPriceLists || data.goodPriceLists.length <= 0){
              showSubmitCommitButton = true
            }
          }else if(data.status == 3){
            showTitle = '核价等待中'
            if(!data.isSubmitCheckPrice){
              showTitle = '核价确认等待中'
              submitCommitButton = '修改'
            }
            if(!data.goodPriceLists || data.goodPriceLists.length <= 0){
              showSubmitCommitButton = true
            }

          }else if(data.status == 4){
            showTitle = '第一次竞价阶段'
            if(data.biddingPushChannelUserIds && (',' + data.biddingPushChannelUserIds + ',').indexOf(',' + this.data.userInfo.userId + ',') > -1){
              data.showBiddingType = true
              inputPricePercent = 0
              totalPrice = 0
              goodList.forEach(item => {
                item.inputPrice = null
              })
            }
          }else if(data.status == 5){
            showTitle = '第二次竞价阶段'
            if(!data.isSubmitBiddingSecondSubmit){
              showTitle = '请尽快报价'
            }else{
              showTitle = '等待公示结果'
            }
            if(!data.biddingStartTwo){
              if(data.channelFirstRank && data.channelFirstRank == 1){
                showTitle = '您目前报价最高，截止至' + endTimeString + '，若无人发起挑战，您将获得本次订单'
              }else if(data.channelFirstRank && data.channelFirstRank != 1){
                showTitle = '您的报价与第一名差距小于' + data.biddingPrice + '或小于' + data.biddingPoint + '%，是否发起挑战'
              }else if(data.channelFirstStatus && data.channelFirstStatus == 3){
                showTitle = '您已失去挑战资格'
              }
            }else if(data.biddingStartTwo && data.biddingStartTwo == 2){
              if(data.channelFirstRank && data.channelFirstRank == 1){
                showTitle = '有其他人发起了挑战，您是否要重新报价？'
              }else if(data.channelFirstRank && data.channelFirstRank != 1){
                showTitle = '有人发起二次竞价，您是否参与'
              }
              if(((',' + data.biddingStartTwoUserIds + ',').indexOf(',' + this.data.userInfo.userId + ',') > -1)){
                hasJoinBidding = 2
                hasAddJoinBidding = 2
                data.isSubmitBiddingSecond = true
                if(data.biddingSecondPrice){
                  showTitle = '等待公示结果'
                }
              }
            }
          }else if(data.status == 9){
            showTitle = '该订单已结束'
          }else if(data.status == 7){
            showTitle = '该订单已结束'
            if(data.lastUserId == this.data.userInfo.userId){
              data.showEndBoolean = 1
            }
          }
        }else if(this.data.userInfo.userType == 2){
          if(data.status == 1){
            showTitle = '请尽快安排核价'
            if(data.isNextPush == 2 && data.pushUserIds && ((',' + data.pushUserIds + ',').indexOf(',' + this.data.userInfo.userId + ',') > -1)){
              // showTitle += '，您没有权利参与竞价'
              hasPushButton = false
            }
            //已分配的核价渠道商
            if(data.pushChannelUserIds){
              data.pushChannelUserIds.split(",").forEach(item => {
                chooseUserList.push(parseInt(item))
              })
            }
          }else if(data.status == 2){
            showTitle = '您的渠道正在核价'
            if(data.isNextPush == 2 && data.pushUserIds && ((',' + data.pushUserIds + ',').indexOf(',' + this.data.userInfo.userId + ',') > -1)){
              // showTitle += '，您没有权利参与竞价'
              hasPushButton = false
            }
            //已分配的核价渠道商
            if(data.pushChannelUserIds){
              data.pushChannelUserIds.split(",").forEach(item => {
                chooseUserList.push(item)
              })
            }
          }else if(data.status == 3){
            showTitle = '等待公司反馈'
            if(data.isNextPush == 2 && data.pushUserIds && ((',' + data.pushUserIds + ',').indexOf(',' + this.data.userInfo.userId + ',') > -1)){
              // showTitle += '，您没有权利参与竞价'
              hasPushButton = false
            }
          }else if(data.status == 4){
            showTitle = '第一次竞价阶段'
            if(!data.biddingOneEndTime){
              showTitle = '等待确认竞价截止时间'
            }else if(!data.biddingPushUserIds){
              showTitle = '等待推送渠道'
            }else if(data.biddingPushUserIds){
              if((',' + data.biddingPushUserIds + ',').indexOf(',' + this.data.userInfo.userId + ',') > -1){
                if(data.biddingHasPushUserIds){
                  if((',' + data.biddingHasPushUserIds + ',').indexOf(',' + this.data.userInfo.userId + ',') > -1){
                    showTitle = '你的渠道正在竞价'
                    data.biddingHasPushUserIdsStatus = true
                  }else{
                    showTitle = '等待分配渠道'
                  }
                }
              }else{
                // showTitle = '您没有权利参与竞价'
              }
            }
            if(data.isNextPush == 2 && data.pushUserIds && ((',' + data.pushUserIds + ',').indexOf(',' + this.data.userInfo.userId + ',') > -1)){
              // showTitle += '，您没有权利参与竞价'
              hasPushButton = false
            }
          }else if(data.status == 5){
            showTitle = '第二次竞价阶段'
            if(data.isNextPush == 2 && data.pushUserIds && ((',' + data.pushUserIds + ',').indexOf(',' + this.data.userInfo.userId + ',') > -1)){
              // showTitle += '，您没有权利参与竞价'
              hasPushButton = false
            }
          }else if(data.status == 9){
            showTitle = '该订单已结束'
          }else if(data.status == 7){
            showTitle = '该订单已确定渠道商'
            if(data.isBlindBox == 2){
              showTitle = '该订单已确定盲盒'
            }
            let name = ''
            if((!data.channelUserSecondBiddingListDTOS || data.channelUserSecondBiddingListDTOS.length <= 0) && data.channelUserFirstBiddingListDTOS && data.channelUserFirstBiddingListDTOS.length > 0){
              data.channelUserFirstBiddingListDTOS.forEach(item => {
                if(item.rankNum == 1 && item.pioneerId == this.data.userInfo.userId){
                  name = item.channelName
                }
              })
            }
            if(data.channelUserSecondBiddingListDTOS && data.channelUserSecondBiddingListDTOS.length > 0){
              data.channelUserSecondBiddingListDTOS.forEach(item => {
                if(item.status == 2){
                  name = item.channelName
                }
              })
            }
            data.showEndName = name
          }
        }
        const getStatusName = (item) => {
          const status = item.orderStatus
          const orderIsNextPush = item.orderIsNextPush
          const isAbandon = item.isAbandon
          return (orderIsNextPush == 2 ? '已转移，' : (isAbandon == 2 ? '已放弃，' : '')) + this.data.orderStatusName.find(label => label.id == status).sysValueName
        }
        // showTitle = this.getStatusName(data)
        showTitle = getStatusName(data)
        
        let hasChannelRefuseShowing = true
        if (data.channelRefuseIds && (',' + data.channelRefuseIds + ',').indexOf(',' + this.data.userInfo.userId + ',') > -1){
          hasChannelRefuseShowing = false
        }
        
        if(data.channelUserFirstBiddingListDTOS && data.channelUserFirstBiddingListDTOS.length > 0){
          data.channelUserFirstBiddingListDTOS.forEach(item => {
            if(item.createTime){
              item.createDate = formatDateCN(new Date(item.createTime))
            }
          })
        }
        if(data.channelUserSecondBiddingListDTOS && data.channelUserSecondBiddingListDTOS.length > 0){
          data.channelUserSecondBiddingListDTOS.forEach(item => {
            if(item.createTime){
              item.createDate = formatDateCN(new Date(item.createTime))
            }
          })
        }
        if(data.projectMsg.projectOutGoodMsg){
          let outList = JSON.parse(data.projectMsg.projectOutGoodMsg)
          let outJoinList = []
          outList.forEach(item => {
            item.date = formatDateCN(new Date(item.time))
            if(item.userId == this.data.userInfo.userId){
              outJoinList.push(item)
            }
          })
          data.projectOutGoodList = outJoinList
        }
        let refuseChannelUserName = ""
        if(data.channelRefuseIds && this.data.userInfo.userType == 2){
          let refuseChannelUserNameList = data.channelRefuseIds.split(",")
          refuseChannelUserNameList.forEach((item,index) => {
            refuseChannelUserName = refuseChannelUserName + data.channelUserIds[item]
            if(index < refuseChannelUserNameList.length -1){
              refuseChannelUserName = refuseChannelUserName + ","
            }
          })
          refuseChannelUserName = refuseChannelUserName + "已拒绝报价"
        }
        data.isSubmitBiddingFirstSubmit = true
        this.setData({
          tableData: [],
          goodList: []
        })
        if(data.nextPushBeforeChannelUserList && data.nextPushBeforeChannelUserList.length > 0){
          data.nextPushBeforeChannelUserList.forEach(item => {
            if(item.createTime){
              item.createDate = formatDateCN(new Date(item.createTime))
            }
          })
        }
        if(data.channelUserGoodListDTOS && data.channelUserGoodListDTOS.length > 0){
          data.channelUserGoodListDTOS.forEach(item => {
            if(item.createTime){
              item.createDate = formatDateCN(new Date(item.createTime))
            }
          })
        }
        this.setTableData(tableData.slice(0, 110), (tableData.length / 50).toFixed(0) == 0 ? 1 : (tableData.length / 50).toFixed(0), 0)
        this.setGoodList(goodList, (goodList.length / 100).toFixed(0) == 0 ? 1 : (goodList.length / 100).toFixed(0), 0)
        this.setOrderMsg(data)
        
        if(data.fileType){
          let addColumns = [
            // { title: '单价', key: 'inputDiscountShow', width: '200rpx', type: 'input', },
            // { title: '折后单价', key: 'priceShow', width: '200rpx', type: 'input', },
          ]
          if(data.fileType == 2){
            goodColumns = addColumns.concat(this.data.fileType2Columns)
          }else if(data.fileType == 3){
            goodColumns = addColumns.concat(this.data.fileType3Columns)
          }
        }
        this.setData({
          refuseChannelUserName: refuseChannelUserName,
          discountIndex: !data.isDiscount || data.isDiscount == 1 ? 0 : 1,
          columns: columns,
          hasChannelRefuseShowing: hasChannelRefuseShowing,
          // tableData: tableData,
          // orderMsg: data,
          taskAllType: checkedBlindBox,
          // goodList: goodList,
          showTitle: showTitle,
          inputPricePercent: inputPricePercent,
          totalPrice: totalPrice.toFixed(2),
          showType: null,
          endTime: endTime,
          submitCommitButton: submitCommitButton,
          showSubmitCommitButton: showSubmitCommitButton,
          hasPushButton: hasPushButton,
          chooseUserList: chooseUserList,
          goodColumns: goodColumns,
          goodTotalDiscount: goodTotalDiscount,
          goodTotalDiscount2: goodTotalDiscount2.toFixed(2),
          hasJoinBidding: hasJoinBidding,
          hasAddJoinBidding: hasAddJoinBidding,
          leftTime: leftTime,
        })
      }
      setTimeout(function () {
        wx.hideLoading()
      }, 500)
    });
  },
  preciseMultiply(num1, num2, precision = 2) {
    const result = num1 * num2;
    const power = Math.pow(10, precision);
    return (Math.round(result * power) / power).toFixed(precision);
  },
  setOrderMsg(data){
    let pushUserIdsToUserType = false
    if(data.pushUserIds && data.pushUserIds.indexOf(this.data.userInfo.userId) > -1){
      pushUserIdsToUserType = true
    }
    //显示已拒绝的报价信息
    const noChannelRefuserNames = data.channelRefuserNames == null || (Array.isArray(data.channelRefuserNames) && data.channelRefuserNames.length == 0)
    if (!noChannelRefuserNames) data.channelRefuserNames = data.channelRefuserNames.join(',') + '已拒绝报价'
    //处理助理报价列表相关
    const checkMsgListColumns = [...this.data.checkMsgListColumns]
    const isAssistant = this.data.userInfo.userType == 2 && this.data.userInfo.isAssistant == 2
    if (isAssistant) {
      const checkCostPriceColumnIndex = checkMsgListColumns.findIndex(col => col.key == 'checkCostPrice')
      checkMsgListColumns.splice(checkCostPriceColumnIndex, 1)
      const checkRemarkColumnIndex = checkMsgListColumns.findIndex(col => col.key == 'checkRemark')
      checkMsgListColumns.splice(checkRemarkColumnIndex, 1)
      checkMsgListColumns.unshift({ title: '渠道名称', key: 'channelName', width: '200rpx', type: 'text'})
    }
    //处理开拓者助理核价
    const noAssistantCheckList = data.assistantCheckList == null || (Array.isArray(data.assistantCheckList) && data.assistantCheckList.length == 0)
    !noAssistantCheckList && (() => {
      data.assistantCheckList.forEach(item => {
        item.createTime && (item.createDate = formatDateCN(new Date(item.createTime)))
      })
    })()
    const noChannelUserGoodListDTOS = data.channelUserGoodListDTOS == null || (Array.isArray(data.channelUserGoodListDTOS) && data.channelUserGoodListDTOS.length == 0)

    this.setData({
      orderMsg: data,
      pushUserIdsToUserType: pushUserIdsToUserType,
      checkMsgListColumnsx: checkMsgListColumns,
      // confirmBtnShow: !noChannelUserGoodListDTOS || !noAssistantCheckList,
      noChannelUserGoodListDTOS: noChannelUserGoodListDTOS,
      noAssistantCheckList: noAssistantCheckList
    })
  },
  setGoodList(goodList, totalNum, pageNum){
    // console.log("数量===》", totalNum, pageNum)
    let list = JSON.parse(JSON.stringify(goodList))
    let a = list.slice(pageNum * 100, (pageNum + 1) * 100)
    if(pageNum <= totalNum){
      this.setData({
        goodList: this.data.goodList.concat(a)
      })
      // console.log("列表数量====>", this.data.goodList.length)
      if(pageNum < totalNum){
        setTimeout(()=>{
          this.setGoodList(goodList, totalNum, pageNum + 1)
        }, 200)
      }
    }
  },
  setTableData(tableData, totalNum, pageNum){
    let list = JSON.parse(JSON.stringify(tableData))
    let a = list.slice(pageNum * 100, (pageNum + 1) * 100)
    if(pageNum <= totalNum){
      this.setData({
        tableData: this.data.tableData.concat(a)
      })
      setTimeout(()=>{
        this.setTableData(tableData, totalNum, pageNum + 1)
      }, 200)
    }
  },
  
  previewSkuPic(row){
    let item = row.currentTarget.dataset.item
    if(item.goodSkuPic){
      wx.previewImage({
        current: '', // 当前显示图片的http链接
        urls: [item.goodSkuPic] // 需要预览的图片http链接列表
      })
    }
  },
  copySkuText(e){
    wx.setClipboardData({
      data:e.currentTarget.dataset.text,//要复制的数据
      success (res) {
        wx.showToast({
          title: "复制成功",
          icon: "none"
        });
      }
   })
  },

  // 查看其他订单信息
  goShowOtherOrderMsg(e){
    let orderId = e.currentTarget.dataset.id
    let projectName = e.currentTarget.dataset.name
    wx.navigateTo({
      url: '/pages/orderMsg/orderMsg?toOrder=2&orderId='+ orderId + '&projectName=' + projectName + '&orderStatusName=' + JSON.stringify(this.data.orderStatusName),
    })
  },
  goPricing(e) {
    this.setData({
      showType: 10
    })
  },
  discountGoodTypeChange(e) {
    console.log(e)
  },
  submitPricing() {
    const params = {
        cashDiscountType: 0,
        checkCashPrice: "",//变现价格
        checkRemark: "",
        costDiscountType: 0,
        checkCostPrice: "",//建议成本
        orderId: this.data.orderMsg.id
    }
    server.post("/app/user/sureChannelCheckPrice", params).then(res => {
      if (res.key === 1000) {
        this.getOrderMsg()
        wx.showToast({
          title: '提交成功',
          icon: 'success',
          duration: 3000
        })
        this.setData({
          showType: null
        })
      }
    });
    wx.hideLoading()
    
  },

  // 选择框事件
  selectOnConfirm(e) {

  },
  // 打开更多操作弹窗
  handleShowDialog(e) {
    setTimeout(() => {
      if (!this.data.showDialog) {
        this.setData({
          showDialog: true
        })
      }
    })
  },
  // 关闭更多操作弹窗
  handleAnimationEnd(e) {
    this.setData({
      showDialog: false
    })
  },
  // 监听页面点击
  handlePage() {
    // 如果更多操作弹窗打开，点击页面关闭
    if (this.data.showDialog) {
      let component = this.selectComponent('#selectDialog')
      component.hide()
    }
  },
  // 获取当前日期
  getNowDate() {
    const date = new Date()
    const year = date.getFullYear()
    const month = date.getMonth() + 1
    const day = date.getDate()
    const hour = date.getHours()
    const minute = date.getMinutes()
    const halfHour = '00'
    const halfMinute = '00'
    if(this.data.date){
      let a = this.data.date.split("-")
      if(a[0] == year && a[1] == month && a[2] == day){
        halfHour = new Date(date.setHours(hour, minute + 30)).getHours()
        halfMinute = new Date(date.setHours(hour, minute + 30)).getMinutes()
      }
    }
    this.setData({
      startDateString: `${year}-${month}-${day}`,
      startTimeString: `${halfHour}:${halfMinute}`,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if(options.orderId){
      let toOrder = 1
      if(options.toOrder){
        toOrder = options.toOrder
      }
      this.setData({
        orderId: options.orderId,
        projectName: options.projectName,
        toOrder: toOrder,
      })
    }
    if(options.orderStatusName) {
      const orderStatusName = JSON.parse(options.orderStatusName)
      // console.log(orderStatusName)
      this.setData({
        orderStatusName: orderStatusName
      })
    }
    this.getOrderMsg();
    this.getNowDate();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      pageShow: true
    })
    if(wx.getStorageSync('userInfo')){
      let userInfo = wx.getStorageSync('userInfo')
      this.setData({
        userInfo: wx.getStorageSync('userInfo'),
        showName: userInfo.telephone,
      })
    }
    var projectName = wx.getStorageSync('projectName')
    wx.setNavigationBarTitle({
      title: projectName,
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    // let that = this
    // let obj = {
    //   toOrder: that.toOrder,
    //   orderId: that.orderId,
    //   projectName: that.projectName,
    // }
    // const pages = getCurrentPages()     //获取页面列表
    // console.log("pages===>", pages, pages.length)
    // const perpage = pages[pages.length - 1]    //当前页   
    // perpage.onLoad(obj)
    this.getOrderMsg()
    wx.stopPullDownRefresh();
  },
  

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '牧鲸选品',
      path: `pages/orderMsg/orderMsg?orderId=${this.data.orderId}&projectName=${this.data.projectName}&orderStatusName=${JSON.stringify(this.data.orderStatusName)}`,
      imageUrl: '/images/share.jpg'
    }
  }
})